home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEX-UTIL / DVI_DVI1 / dvilj / c / findfile < prev    next >
Text File  |  1996-02-20  |  5KB  |  193 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "config.h"
  5. #include "fromosl.h"
  6.  
  7.  
  8. /* #define FIND_DEBUG */
  9.  
  10. #define PATH_NOT_PRESENT 248 /* In case TeXFonts: isn't known */
  11.  
  12.  
  13. #ifdef RISC_USE_OSL
  14. #define TO_META_FILE   emsize = sprintf
  15. #define TO_META_DEST   embuf
  16. #define TO_META_FLUSH  write_multi(embuf,1,emsize,metafile);
  17. #else
  18. #define TO_META_FILE   fprintf
  19. #define TO_META_DEST   metafile
  20. #define TO_META_FLUSH
  21. #endif
  22.  
  23. #define METAFONTFILE_EXTENSION  "lj-fonts"
  24. #define METAFONTFILE_FIRSTLINE  "wimpslot 960k"
  25.  
  26. #define MFMODE600 "ljiv"
  27. #define MFMODE300 "hplaser"
  28.  
  29.  
  30. void Fatal();
  31. void *xosfile_set_type(char *, int);
  32.  
  33.  
  34. extern char embuf[STRSIZE];
  35. extern int emsize;
  36. extern char filename[STRSIZE];
  37. extern char MFFileName[STRSIZE];
  38. extern FILEPTR metafile;
  39. extern long4 RESOLUTION;
  40.  
  41.  
  42. /* Finds font files */
  43. bool findfile(char *path, char *name, long4 font_mag, char *full_name, bool mode, int number)
  44. {
  45.   os_f fp;
  46.   long4 mag;
  47.   int spare;
  48.   os_error *ose;
  49.  
  50.   fp = 0;
  51.   if (mode == _TRUE) {sprintf(full_name,"%s%s.tfm",path,name);}
  52.   else {mag = (10*font_mag+25)/50; sprintf(full_name,"%s%s.%dpk",path,name,mag);}
  53.   ose = xosfind_openin(0x43,full_name,path,&fp);
  54.   if (ose != NULL)
  55.   {
  56.     if (ose->errnum == PATH_NOT_PRESENT) {Fatal("Error #%d: %s\n",ose->errnum, ose->errmess);}
  57.     else {return(_FALSE);}
  58.   }
  59.   if (fp != FPNULL)
  60.   {
  61.     ose = xosargs_read_path(fp,full_name,STRSIZE,&spare);
  62.     if (ose != NULL) {return(_FALSE);} /* incredible but true: this happens! */
  63.     /* full_name[STRSIZE-spare] = 0;*/
  64.     xosfind_close(fp);
  65.     #ifdef FIND_DEBUG
  66.     printf("findfile: open <%s> OK.\n",full_name);
  67.     #endif
  68.     return(_TRUE);
  69.   }
  70.   else if (mode == _FALSE)
  71.   {
  72.     sprintf(full_name,"%s%s.%dpxl",path,name,mag);
  73.     ose = xosfind_openin(0x43,full_name,path,&fp);
  74.     if (ose != NULL)
  75.     {
  76.       if (ose->errnum == PATH_NOT_PRESENT) {Fatal("Error #%d: %s\n",ose->errnum, ose->errmess);}
  77.       else {return(_FALSE);}
  78.     }
  79.     if (fp != FPNULL)
  80.     {
  81.       ose = xosargs_read_path(fp,full_name,STRSIZE,&spare);
  82.       if (ose != NULL) {return(_FALSE);}
  83.       /*full_name[STRSIZE-spare] = 0;*/
  84.       xosfind_close(fp);
  85.       #ifdef FIND_DEBUG
  86.       printf("findfile: open <%s> OK.\n",full_name);
  87.       #endif
  88.       return(_TRUE);
  89.     }
  90.   }
  91.   #ifdef FIND_DEBUG
  92.   printf("findfile: open <%s> ERROR!\n",full_name);
  93.   #endif
  94.   return(_FALSE);
  95. }
  96.  
  97.  
  98. /* Mimics UNIX-Lib's access-function */
  99. int access(char *name, int flag)
  100. {
  101.   int obj_type,load_addr,exec_addr,size,actflag;
  102.   bits attr;
  103.   os_error *ose;
  104.  
  105.   ose = xosfile_read(name,&obj_type,&load_addr,&exec_addr,&size,&attr);
  106.   if (ose != NULL) {return(-1);}
  107.   if (obj_type == 0) {return(-1);}
  108.   actflag = ((attr & 0x20) >> 4) || ((attr & 0x10) >> 2) ||
  109.                       (attr & 2) || ((attr & 0) << 2);
  110.   if ((actflag & 2) != 0) {actflag |= 1;}
  111.   if (flag == actflag) {return(0);}
  112.   else {return(-1);}
  113. }
  114.  
  115.  
  116.  
  117. /* (Creates a taskobey file and) appends commands to create missing fonts
  118.    to taskobey file. */
  119. void MakeMetafontFile(char *path, char *name, int fontmag)
  120. {
  121.   os_f fp;
  122.   int i,j,k;
  123.   os_error *ose;
  124.   char mfname[STRSIZE];
  125.   double mag;
  126.   char mode[16];
  127.  
  128.   fp = 0;
  129.   sprintf(mfname,"%s%s.mf",path,name);
  130.   /* This shouldn't produce serious errors; those would have appeared
  131.      in the previous call to <findfile> */
  132.   if ((ose = xosfind_openin(0x43,mfname,path,&fp)) == NULL)
  133.   {
  134.     if (fp == 0) {printf("You're missing the metafont file for font <%s>!\n",name); return;}
  135.     if ((ose = xosargs_read_path(fp,mfname,STRSIZE,&i)) == NULL)
  136.     {
  137.       i = 0; j = 0;
  138.       while ((k = mfname[i++]) != '\0') {
  139.         if (k == '.') {j = i;}
  140.       }
  141.       mfname[j] = '\0';
  142.       if (metafile == FPNULL)
  143.       {
  144.         /* Strip "lj" of emitfile, append Metafontfile-extension instead */
  145.         i=0; j=0;
  146.         while ((k = filename[i]) != '\0') {
  147.           MFFileName[i++] = k; if (k == '.') {j = i;}
  148.         }
  149.         sprintf(&MFFileName[j],"%s",METAFONTFILE_EXTENSION);
  150.         if ((metafile = BOUTOPEN(MFFileName)) == FPNULL) {
  151.           printf("Error opening metafont command file <%s>!\n",MFFileName);
  152.           xosfind_close(fp); return;
  153.         }
  154.         xosfile_set_type(MFFileName,0xfd7); /* Task obey */
  155.         TO_META_FILE(TO_META_DEST,"%s\n",METAFONTFILE_FIRSTLINE); TO_META_FLUSH;
  156.       }
  157.       if (RESOLUTION == 600) {strcpy(mode,MFMODE600);}
  158.                         else {strcpy(mode,MFMODE300);}
  159.       i = (10*fontmag + 25)/50; mag = ((double)i)/RESOLUTION;
  160.       TO_META_FILE(TO_META_DEST,"virmf &plain \\mode=%s; mag=%f; input %smf\n",mode,mag,mfname);
  161.       TO_META_FLUSH;
  162.       TO_META_FILE(TO_META_DEST,"gftopk %s%dgf %s%dpk\n",mfname,i,mfname,i); TO_META_FLUSH;
  163.       TO_META_FILE(TO_META_DEST,"wipe %s%dgf F~C~V\n",mfname,i); TO_META_FLUSH;
  164.       TO_META_FILE(TO_META_DEST,"wipe %slog F~C~V\n",mfname); TO_META_FLUSH;
  165.     }
  166.     xosfind_close(fp);
  167.   }
  168.   if (ose != NULL) {printf("Error (&%x): %s\n",ose->errnum,ose->errmess); return;}
  169. }
  170.  
  171.  
  172. #ifdef RISC_USE_OSL
  173.  
  174. /* Mimics fseek */
  175. int os_seek(os_f fp, long int rel, int whence)
  176. {
  177.   register int size, pos;
  178.  
  179.   size = osargs_read_ext(fp);
  180.   switch(whence) {
  181.     case SEEK_SET: pos = rel; break;
  182.     case SEEK_CUR: pos = osargs_read_ptr(fp) + rel; break;
  183.     case SEEK_END: pos = size + rel; break;
  184.     default: pos = -1;
  185.   }
  186.   if ((pos < 0) || (pos > size)) {return(1);} /*
  187.   if (pos < 0)    {osargs_set_ptr(fp,0);    return(1);}
  188.   if (pos > size) {osargs_set_ptr(fp,size); return(1);}*/
  189.   osargs_set_ptr(fp,pos); return(0);
  190. }
  191.  
  192. #endif
  193.